﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using S4Store.Models.Report;
using S4Store.Domain;
using S4Store.Service;
using S4Store.Domain.AfterSaleKpi;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;
using S4Store.Models;
using S4Store.Models.AfterSaleReport;

namespace S4Store.Controllers
{
    public class AfterSellerReportController :  ReportBaseController
    {
        //
        // GET: /AfterSellerReport/
        public AfterSaleCarKPIService AfterSaleCarKPIService { get; set; }
        public S4Store.Service.EmployeeService EmployeeService { get; set; }

        public ActionResult Index()
        {
            AfterSaleHealthyCarTypeModel model = new AfterSaleHealthyCarTypeModel();
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.应时台次 = (int)((decimal)AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargets(Month.Year, Month.Month, SAemploys).Where(o => o.IsConfirmed).Sum(o => o.BYWXRCTCMB_MaintenceCarToFactoryTarget) * 时间进度);

                model.实际台次 = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputs(Month.Year, Month.Month, SAemploys).Where(o => o.IsConfirmed).Sum(o => o.WXRCTC_MaintentceToFactory);

                model.实际产值 = Math.Round(AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputs(Month.Year, Month.Month, SAemploys).Where(o => o.IsConfirmed).Sum(o => o.WXCZ_MaintenceValue), 2, MidpointRounding.AwayFromZero);

                model.应时产值 = Math.Round(AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargets(Month.Year, Month.Month, SAemploys).Where(o => o.IsConfirmed).Sum(o => o.BYWXCZMB_MaintenceValueTarget) * 时间进度, 2, MidpointRounding.AwayFromZero);

                ViewBag.时间进度 = 时间进度;

                this.InjectReportModel(model);
                model.BarModel.Action = "Index";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        #region  常规维修动态-人员查询
        public ActionResult Seller_RCTCCY()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {
                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();


                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();

                ViewBag.时间进度 = 时间进度;

                this.InjectReportModel(model);
                model.BarModel.Action = "Seller_RCTCCY";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt() }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CS", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult Seller_RCTCCYXXX(int sellerid)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;

            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {
                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed &&  SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();

                ViewBag.时间进度 = 时间进度;

                model.TimeRate = new Models.Chart.Pie();
                model.TimeRate.Width = 450;
                model.TimeRate.Height = 300;
                model.TimeRate.IsRate = true;
                model.TimeRate.YAxis = "%";
                model.TimeRate.Name = "时间进度";
                model.TimeRate.Data.Add("时间进度", 时间进度);
                model.TimeRate.Data.Add("剩余", 1 - 时间进度);

                this.InjectReportModel(model);
                model.BarModel.Action = "Seller_RCTCCYXXX";
                model.BarModel.Controller = "AfterSellerReport";
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>常态维修动态>人员查询>入场台次完成进度差" }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("Seller_RCTCCYXXXHistory", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
				}else
		{
			  model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("Seller_RCTCCYXXXHistory", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
			}
                model.BarModel.RemoveView(ReportBarModel.ViewItem.Stores);
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                model.BarModel.SearchSellerId = sellerid;
                t.Commit();
            }
            return View(model);
        }

        public ActionResult Seller_RCTCCYXXXHistory(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;

            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, End.Value.LastOrNowDay());
            }

            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month <= end && o.AddTime >= start).ToList();
                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month <= end && o.AddTime >= start).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "Seller_RCTCCYXXXHistory";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.RemoveView(ReportBarModel.ViewItem.Stores);
                model.BarModel.SearchSellerId = sellerid;
                t.Commit();
            }
            return View(model);
        }

        #endregion


        #region 维修产值 Seller_WXCZ
        public ActionResult Seller_WXCZ()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {
                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();


                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();

                ViewBag.时间进度 = 时间进度;

                this.InjectReportModel(model);
                model.BarModel.Action = "Seller_WXCZ";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>常态维修动态>人员查询>维修产值完成进度差"}) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CS", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult Seller_WXCZXXX(int sellerid)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;

            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {
                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();

                ViewBag.时间进度 = 时间进度;

                model.TimeRate = new Models.Chart.Pie();
                model.TimeRate.Width = 450;
                model.TimeRate.Height = 300;
                model.TimeRate.IsRate = true;
                model.TimeRate.YAxis = "%";
                model.TimeRate.Name = "时间进度";
                model.TimeRate.Data.Add("时间进度", 时间进度);
                model.TimeRate.Data.Add("剩余", 1 - 时间进度);

                this.InjectReportModel(model);
                model.BarModel.Action = "Seller_WXCZXXX";
                model.BarModel.Controller = "AfterSellerReport";
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>常态维修动态>人员查询>维修产值完成进度差"}) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("Seller_WXCZXXXHistory", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
				}else
		{
			 model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("Seller_WXCZXXXHistory", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
			}
                model.BarModel.RemoveView(ReportBarModel.ViewItem.Stores);
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                model.BarModel.SearchSellerId = sellerid;
                t.Commit();
            }
            return View(model);
        }

        public ActionResult Seller_WXCZXXXHistory(int sellerid = 0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;

            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, End.Value.LastOrNowDay());
            }

            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month <= end && o.AddTime >= start).ToList();
                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(sellerid) && o.EmployeeId == sellerid && Month <= end && o.AddTime >= start).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "Seller_WXCZXXXHistory";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.RemoveView(ReportBarModel.ViewItem.Stores);
                model.BarModel.SearchSellerId = sellerid;
                t.Commit();
            }
            return View(model);
        }
        #endregion

        #region 前台服务
        public ActionResult FrontServiceIndex()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());
                ViewBag.时间进度 = 时间进度;
                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year==Month.Year && o.AddTime.Month==Month.Month).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == Month.Year && o.AddTime.Month == Month.Month).ToList();

                this.InjectReportModel(model);
                model.BarModel.Action = "FrontServiceIndex";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='人员查询' href='" + Url.Action("FrontService_RYCX") + "' ><span>人员查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult FrontService_RYCX()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());
                ViewBag.时间进度 = 时间进度;
                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == Month.Year && o.AddTime.Month == Month.Month).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == Month.Year && o.AddTime.Month == Month.Month).ToList();

                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_RYCX";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='人员查询' href='" + Url.Action("FrontService_RYCX") + "' ><span>人员查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult FrontService_RYXXX(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());
                ViewBag.时间进度 = 时间进度;
                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs().Where(o => o.StoreId == Store.Id && o.Month.Year==Month.Year && o.Month.Month ==Month.Month).ToList();


                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == Month.Year && o.AddTime.Month == Month.Month && o.EmployeeId==sellerid).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == Month.Year && o.AddTime.Month == Month.Month && o.EmployeeId==sellerid).ToList();

                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_RYXXX";
                model.BarModel.Controller = "AfterSellerReport";
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>前台SA>人员查询" }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a target='navtab' class='historyrecord' title='历史查询' href='" + Url.Action("FrontService_KHGLSLHistory", new { sellerid = sellerid }) + "' ><span>历史查询</span></a>";
				}else
		{
			 model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='历史查询' href='" + Url.Action("FrontService_KHGLSLHistory", new { sellerid = sellerid }) + "' ><span>历史查询</span></a>";
			}
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                model.BarModel.SearchSellerId = sellerid;
                t.Commit();

            }
            return View(model);
        }

        

        public ActionResult FrontService_KHGLSLHistory(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }

            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs(Store.Id).Where(o => o.Month <= end && o.Month >= start).ToList();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime<=end && o.AddTime>=start && o.EmployeeId == sellerid).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start && o.EmployeeId == sellerid).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_KHGLSLHistory";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CSHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.SearchSellerId = sellerid;

                t.Commit();

            }
            return View(model);
        }

        public ActionResult FrontService_KHGLNLHistory(int sellerid = 0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }

            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs(Store.Id).Where(o => o.Month <= end && o.Month >= start).ToList();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start && o.EmployeeId == sellerid).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start && o.EmployeeId == sellerid).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_KHGLNLHistory";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CSHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.SearchSellerId = sellerid;

                t.Commit();

            }
            return View(model);
        }

        public ActionResult FrontService_KHGLXGHistory(int sellerid = 0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }

            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs(Store.Id).Where(o => o.Month <= end && o.Month >= start).ToList();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start && o.EmployeeId == sellerid).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start && o.EmployeeId == sellerid).ToList();

                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_KHGLXGHistory";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CSHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.SearchSellerId = sellerid;

                t.Commit();

            }
            return View(model);
        }


        public ActionResult FrontService_ZLSSL()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                var curDate = new DateTime(Month.Year, Month.Month, 1);

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);
                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs().Where(o => o.StoreId == Store.Id && o.Month <= end && o.Month >= start).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();

                model.SADayData = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime<=end && o.AddTime>=start).ToList();


                ViewBag.时间进度 = 时间进度;


                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_ZLSSL";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.Start = start;
                model.BarModel.End = end;
                //model.BarModel.SearchCarBrandId = brandid;
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>前台SA>招徕实施率" }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a>";
		}
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                
                t.Commit();

            }
            return View(model);
        }

        public ActionResult FrontService_YYCGL()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                var curDate = new DateTime(Month.Year, Month.Month, 1);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);
                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs().Where(o => o.StoreId == Store.Id && o.Month <= end && o.Month >= start).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();

                model.SADayData = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start).ToList();


                ViewBag.时间进度 = 时间进度;


                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_YYCGL";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.Start = start;
                model.BarModel.End = end;
                //model.BarModel.SearchCarBrandId = brandid;
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>前台SA>预约成功率" }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a>";
		}
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);


                t.Commit();

            }
            return View(model);
        }


        public ActionResult FrontService_YXLSL()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                var curDate = new DateTime(Month.Year, Month.Month, 1);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);
                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs().Where(o => o.StoreId == Store.Id && o.Month <= end && o.Month >= start).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();

                model.SADayData = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start).ToList();


                ViewBag.时间进度 = 时间进度;


                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_YXLSL";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.Start = start;
                model.BarModel.End = end;
                //model.BarModel.SearchCarBrandId = brandid;
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>前台SA>隐形流失率" }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a>";
		}
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);


                t.Commit();

            }
            return View(model);
        }

        public ActionResult FrontService_SSLSL()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                var curDate = new DateTime(Month.Year, Month.Month, 1);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);
                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs().Where(o => o.StoreId == Store.Id && o.Month <= end && o.Month >= start).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.MonthTargets = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();

                model.SADayData = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime.Year == curDate.Year && o.AddTime.Month == curDate.Month).ToList();
                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start).ToList();


                ViewBag.时间进度 = 时间进度;


                this.InjectReportModel(model);
                model.BarModel.Action = "FrontService_SSLSL";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.Start = start;
                model.BarModel.End = end;
                //model.BarModel.SearchCarBrandId = brandid;
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>前台SA>事实流失率" }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a>";
				}
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);


                t.Commit();

            }
            return View(model);
        }

        #endregion

        #region 后台服务
        public ActionResult BackServiceIndex()
        {
            //TODO
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);


                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();
                int[] csemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] wmemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();

                var queryConfig = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthConfig(Month.Year, Month.Month, Store.Id);
                if (queryConfig == null) queryConfig = new AfterSaleServiceAdvisorMonthConfig();
                var queryTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargets(Month.Year, Month.Month, employs);
                var queryDayData = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputs(Month.Year, Month.Month, employs);

                model.MonthConfig = queryConfig;
                model.MonthTarget = queryTarget;
                model.SADayDatas = queryDayData;
                model.CSDayDatas = AfterSaleCarKPIService.GetAfterSaleCustomerServiceDayInputs(Month.Year, Month.Month, csemploys);
                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputs(Month.Year, Month.Month, wmemploys);

                 

                ViewBag.时间进度 = 时间进度;

                this.InjectReportModel(model);
                model.BarModel.Action = "BackServiceIndex";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        //
        public ActionResult BackService_LSKHHGL()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();
                int[] wmemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.CSDayDatas = AfterSaleCarKPIService.GetAfterSaleCustomerServiceDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && DateTime.Now.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();
                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();

                
                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputs(Month.Year, Month.Month, wmemploys);


                ViewBag.时间进度 = 时间进度;


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_LSKHHGL";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.Start = start;
                model.BarModel.End = end;
                //model.BarModel.SearchCarBrandId = brandid;
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>客服CR>流失客户率" }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CS", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
				}else
		{
			 model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CS", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
			}
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        /// <summary>
        /// 人员查询
        /// </summary>
        /// <returns></returns>
        public ActionResult BackService_CS()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.CSDayDatas = AfterSaleCarKPIService.GetAfterSaleCustomerServiceDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && DateTime.Now.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_CS";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt() }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CS", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult BackService_CSXXX(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.CSDayDatas = AfterSaleCarKPIService.GetAfterSaleCustomerServiceDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && DateTime.Now.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();
                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_CSXXX";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CSHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                model.BarModel.SearchSellerId = sellerid;

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult BackService_CSHistory(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;

            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }

            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.AccountSpecialist).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs(Store.Id).Where(o=>o.Month<=end && o.Month>=start).ToList();

                model.CSDayDatas = AfterSaleCarKPIService.GetAfterSaleCustomerServiceDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && o.AddTime >= start && o.AddTime <= end).ToList();

                model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime >= start && o.AddTime <= end).ToList();

                model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId) && o.AddTime >= start && o.AddTime <= end).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_CSHistory";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CSHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.SearchSellerId = sellerid;

                t.Commit();

            }
            return View(model);
        }

        /// <summary>
        /// 一次修复率
        /// </summary>
        /// <returns></returns>
        public ActionResult BackService_YCXFL()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.WMDayDatasHistory = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && o.AddTime >= start && o.AddTime <= end).ToList();

                //model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();
                //model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();


                ViewBag.时间进度 = 时间进度;


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_YCXFL";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.Start = start;
                model.BarModel.End = end;
                //model.BarModel.SearchCarBrandId = brandid;
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>客服CR>一次修复率"}) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_WM", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
				}else
		{
			  model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_WM", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
			}
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult BackService_WM()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_WM";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt() }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CS", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }


        public ActionResult BackService_WMXXX(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.WMMonthConfigs = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerMonthConfigs(Month.Year, Month.Month, employs);

                //model.WMDayDatasHistory = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && o.AddTime >= start && o.AddTime <= end).ToList();



                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_WMXXX";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_WMHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                model.BarModel.SearchSellerId = sellerid;

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }


        public ActionResult BackService_WMHistory(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }

            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs(Store.Id).Where(o => o.Month <= end && o.Month >= start).ToList();

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start).ToList();
                model.WMMonthConfigs = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerMonthConfigs(employs).Where(o => o.IsConfirmed && o.AddTime <= end && o.AddTime >= start).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_WMHistory";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CSHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.SearchSellerId = sellerid;

                t.Commit();

            }
            return View(model);
        }

        public ActionResult BackService_ZSJCL()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }
            using (var t = new Transtion())
            {

                decimal 时间进度 = (decimal)Month.LastOrNowDay() / (decimal)(Month.LastDay());

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.WMDayDatasHistory = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && o.AddTime >= start && o.AddTime <= end).ToList();

                //model.MonthTarget = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorMonthTargetsQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();
                //model.SADayDatas = AfterSaleCarKPIService.GetAfterSaleServiceAdvisorDayInputQuery().Where(o => o.IsConfirmed && SAemploys.Contains(o.EmployeeId)).ToList();


                ViewBag.时间进度 = 时间进度;


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_ZSJCL";
                model.BarModel.Controller = "AfterSellerReport";
                model.BarModel.Start = start;
                model.BarModel.End = end;
                //model.BarModel.SearchCarBrandId = brandid;
				if (
                           CurrentUser.Position == S4Store.Domain.Position.SystemManager ||
                           CurrentUser.Position == S4Store.Domain.Position.DealerTutors
                           )
		{
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt()  ,referdesc="售后管理>客户管理动态>客服CR>准时交车率"}) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_WM1", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
				}else
		{
			  model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_WM1", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
			}
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult BackService_WM1()
        {
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_WM1";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("AddImproveGuide", "ImproveGuide", new { guidetype = S4Store.Domain.ImproveGuide.ImproveGuideType.AfterSale.ToInt() }) + "' target='dialog' width='60%'><span >填写改善指导建议</span></a> <a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CS", "AfterSellerReport") + "' target='navtab'><span >人员查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult BackService_WMXXX1(int sellerid=0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;
            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfig = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfig(Month.Year, Month.Month, Store.Id);

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && Month.Year == o.AddTime.Year && o.AddTime.Month == Month.Month).ToList();
                model.WMMonthConfigs = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerMonthConfigs(Month.Year, Month.Month, employs);


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_WMXXX1";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_WMHistory1", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                model.BarModel.SearchSellerId = sellerid;

                //this.InjectReportModel(model);
                //model.BarModel.Action = "BackService_LSKHHGL";
                //model.BarModel.Controller = "AfterSellerReport";
                ////model.BarModel.PlusItem = "<a target='navtab' class='historyrecord' title='销售台次历史记录' href='" + Url.Action("SaleHistroy") + "' ><span>历史数据查询</span></a>";
                //model.BarModel.AddView(ReportBarModel.ViewItem.Month);
                t.Commit();

            }
            return View(model);
        }

        public ActionResult BackService_WMHistory1(int sellerid = 0)
        {
            if (sellerid == 0)
                sellerid = SearchSellerId ?? 0;

            AfterSaleReportServiceAdvisorModel model = new AfterSaleReportServiceAdvisorModel();
            DateTime start = DateTime.Now.AddMonths(-6);
            DateTime end = DateTime.Now;
            if (this.Start != null)
            {
                start = new DateTime(Start.Value.Year, Start.Value.Month, 1);
                end = new DateTime(End.Value.Year, End.Value.Month, 1);
            }

            using (var t = new Transtion())
            {

                t.Inject(AfterSaleCarKPIService);
                t.Inject(EmployeeService);

                int[] employs = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.WorkshopSupervisor).Select(o => o.Id).ToArray();
                int[] SAemploys = EmployeeService.GetEnableEmployee(Store.Id, EmployeeType.ServiceConsultant).Select(o => o.Id).ToArray();

                model.StandardConfigs = AfterSaleCarKPIService.GetAfterSaleMonthStandardConfigs(Store.Id).Where(o => o.Month <= end && o.Month >= start).ToList();

                model.WMDayDatas = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerDayInputQuery().Where(o => o.IsConfirmed && employs.Contains(o.EmployeeId) && o.AddTime <= end && o.AddTime >= start).ToList();
                model.WMMonthConfigs = AfterSaleCarKPIService.GetAfterSaleWorkshopManagerMonthConfigs(employs).Where(o => o.IsConfirmed && o.AddTime <= end && o.AddTime >= start).ToList();


                this.InjectReportModel(model);
                model.BarModel.Action = "BackService_WMHistory1";
                model.BarModel.Controller = "AfterSellerReport";
                //model.BarModel.SearchCarBrandId = brandid;
                //model.BarModel.PlusItem = "<a class='historyrecord edit'  backtype='html' href='" + Url.Action("BackService_CSHistory", "AfterSellerReport", new { sellerid = sellerid }) + "' target='navtab'><span >历史查询</span></a>";
                model.BarModel.AddView(ReportBarModel.ViewItem.StartEnd);
                model.BarModel.Start = start;
                model.BarModel.End = end;
                model.BarModel.SearchSellerId = sellerid;

                t.Commit();

            }
            return View(model);
        }
        #endregion

    }
}
